﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Reflection;

namespace VietPremier.Repository
{
     public class CheckSessionOutAttribute : ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                HttpContext context = HttpContext.Current;

                //check if session is supported
                if (context.Session != null)
                {
                    //check if a new session id was
                    if (context.Session.IsNewSession)
                    {
                        //if it says it is a new session, but an existing cookie exists, then it must
                        // have timed out
                        string sessionCookie = context.Request.Headers["Cookie"];
                        if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
                        {
                            context.Response.Redirect("~/Login/Index");
                        }
                    }
                }
                base.OnActionExecuting(filterContext);
            }
        }
    
}